// 生成一个随机四位数验证码的函数
function generateCaptcha() {
    const captcha = Math.floor(1000 + Math.random() * 9000);
    document.getElementById('captcha-value').innerText = captcha;
}

// 处理登录逻辑的函数
function login() {
    const username = document.getElementById('username').value;
    const password = document.getElementById('password').value;
    const inputCaptcha = document.getElementById('captcha').value;
    const generatedCaptcha = document.getElementById('captcha-value').innerText;

    if (inputCaptcha === generatedCaptcha) {
        alert('登录成功！');
        sessionStorage.setItem('username', username); // 存储用户名到（浏览器）sessionStorage
        window.location.href = 'my.html'; // 登录成功后跳转到 my.html 页面
    } else {
        alert('验证码错误，请重试。');
        generateCaptcha(); // 登录失败时重新生成验证码
    }
}